/* 显示数据Servlet，继承自HttpServlet类 */
/* 无输入参数，直接罗列并返回所有的id和name */

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Example servlet showing request headers
 *
 * @author James Duncan Davidson <duncan@eng.sun.com>
 */

public class Show extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setContentType("text/html;charset=UTF-8"); //规定中文编码，以防乱码
        PrintWriter out = response.getWriter();
        SqlUtil sqlUtil = new SqlUtil();                    //声明工具类对象
        Student[] students = sqlUtil.Query();               //执行查询

        //罗列对象
        for (int i = 0; i < students.length; i++)
        {
            out.println("姓名: " + students[i].getName() + "  ");
            out.println("学号: " + students[i].getId()+ "<br>");
        }
    }

    @Override
    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        doGet(request, response);
    }

}
